package com.credithc.customers.manager.controller;

import com.credithc.baseserv.core.codes.CoreCodes;
import com.credithc.baseserv.core.message.Message;
import com.credithc.baseserv.core.message.MessageFactory;
import com.credithc.baseserv.pageHelper.PageInfo;
import com.credithc.customers.base.po.SystemInfoPo;
import com.credithc.customers.manager.service.SystemInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.HashMap;
import java.util.Map;

/**
 * @Title: 系统标识号
 * @Author: zhq
 * @Date: 2018/12/14
 * @Description: com.credithc.customers.manager.controller
 * @Version: V1.0.0
 */
@RestController
@RequestMapping("/manager/yzt/v1/system/")
public class SystemInfoController {

    @Autowired
    MessageFactory messageFactory;
    @Autowired
    SystemInfoService systemInfoService;

    @GetMapping("/info")
    public Message list(@RequestParam(name = "systemSign", required = false) String systemSign, @RequestParam(name = "pageNo", required = false) Integer pageNo, @RequestParam(name = "pageSize", required = false) Integer pageSize) {
        PageInfo<SystemInfoPo> systemInfoPos = systemInfoService.getList(systemSign, pageNo, pageSize);
        Map<String, Object> pageInfo = new HashMap<>();
        pageInfo.put("pageInfo", systemInfoPos);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, pageInfo);
    }

    @PostMapping("/info/{id}")
    public Message update(@PathVariable(name = "id") String id, @RequestBody SystemInfoPo po) {
        systemInfoService.updateSystemInfo(po, id);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, null);
    }

    @PostMapping("/info")
    public Message saveDictonary(@RequestBody SystemInfoPo po) {
        systemInfoService.insert(po);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS);
    }

    @PostMapping("/info/remove/{id}")
    public Message deleteSys(@PathVariable(name = "id") String id) {
        systemInfoService.deleteSystemById(id);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS);
    }

    /**
     * @param accessed
     * @description: 管理端有效系统字典表查询，屏蔽无效access=2的
     * @author: denghx
     * @date: 2021/5/21 14:08
     * @param: systemSign
     * @return: com.credithc.baseserv.core.message.Message
     */
    @GetMapping("/dictInfo")
    public Message listInfo(@PathParam("systemSign") String systemSign, @PathParam("accessed") String accessed) {
        PageInfo<SystemInfoPo> systemInfoPos = systemInfoService.getDictList(systemSign, accessed);
        Map<String, Object> pageInfo = new HashMap<>();
        pageInfo.put("pageInfo", systemInfoPos);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, pageInfo);
    }

}
